import bisect

n = int(input())
nums = list(map(int, input().split()))
dp = []
for num in nums:
    # 牛马二分
    index = bisect.bisect_left(dp, num)
    if index >= len(dp):
        dp.append(num)
    else:
        dp[index] = num
print(len(dp))
